package com.sharemarking.wa.platform.mapper;

import com.sharemarking.wa.common.entity.PayRecord;
import com.sharemarking.wa.platform.dto.receiptManagement.OrderListDto;
import com.sharemarking.wa.platform.dto.receiptManagement.ReceiptHeadDto;
import com.sharemarking.wa.platform.dto.receiptManagement.ReceiptListDto;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface ReceiptManagementMapper {

    @Select("SELECT CONCAT ('废品运输，',CONCAT(c.province,c.city,c.area,c.city,c.address) ,'到',CONCAT(b.province,b.city,b.area,b.city,b.address)) FROM wa_order a LEFT JOIN wa_order_address b ON a.id = b.order_id  \n" +
            "LEFT JOIN wa_order_address c ON a.parent_id = c.order_id  \n" +
            "WHERE a.code = #{code} AND b.type = 1 AND c.type = 0\n")
    String getAllAddressByCode(String code);


    List<OrderListDto> getOrderList(Map map);
    Integer getOrderListTotal(Map map);
    String getCodeByReceiptId(Integer id);
    ReceiptListDto getReceiptByCode(String code);

    List<ReceiptListDto> getReceiptList(Map map);
    Integer getReceiptListTotal(Map map);

    Integer getPayRecordIdByCode(String code);

    Integer isReceipt(String code);

    @Select("SELECT id AS headId,name,tax_number,addressee_mobile AS mobile,addressee_email AS email " +
            "FROM sys_receipt_head WHERE member_id = #{memberId}")
    ReceiptHeadDto getReceiptHead(Integer memberId);


    Integer getTotalAmount(List<Integer> list);

    @Update("UPDATE sys_pay_record SET is_receipt = #{isReceipt},update_date = #{updateDate} WHERE id = #{id}")
    void updatePayRecordReceipt(PayRecord payRecord);
}
